<?php

/*
Zoo Management Simulation
This file determines the admin page actions by deleting, adding and editing cages
Extra functionality includes locking all doors and setting the maximum cages
*/

include("dbconnect.php");

if ($_REQUEST['submit'] === "Return to Zoo page"){
	header('Location: index.php');
}

if ($_REQUEST['submit'] == "Add cage")
{
	header('Location: addCage.html');
}

if ($_REQUEST['submit'] == "Delete")
{
	$enclosureid = $_REQUEST['id'];
	$deleteentrysql = "DELETE FROM Entry WHERE enclosureId=".$enclosureid;
	$dbh->exec($deleteentrysql);

	$deletesql = "DELETE FROM Enclosure WHERE enclosureId=".$enclosureid;
	$dbh->exec($deletesql);
	header('Location: setupAdmin.php');
}

if ($_REQUEST['submit'] == "Edit")
{
	$enclosureid = $_REQUEST['id'];
	header("Location: editCage.php?cageid=".$enclosureid);
	}

if ($_REQUEST['submit'] == "Lock all doors")
{
	$closesql = "UPDATE entry SET isEntryOpen=0 WHERE isEntryOpen = 1";
	$locksql = "UPDATE enclosure SET isEnclosureLocked=1 WHERE isEnclosureLocked=0";
	$dbh->exec($closesql);
	$dbh->exec($locksql);
	header('Location: index.php');
}
	$dbh = null;?>